<?php


?>
<style>
    .table td.col_amt {
        text-align: right; 
    }
</style>
    
<div class="page-header">
    <h3 class="remove-line-height">Transaction History</h3>
</div>

    <?php
    if(!empty($transactData)){
    ?>
    <div style="margin-bottom: 10px;">
        <a href="javascript:void(0);" id="print_btn" class="btn btn-primary"><i class="icon-print"></i> Print All Transaction History</a>
    </div>
    <?php
    }
    ?>

<table class="table table-striped data-table table-bordered">
    <thead>
        <tr>
            <!--<th colspan="2"><?php /*echo $this->Paginator->sort('Transaction Type', 'MemberGame.start_dt'); */?></th>-->
            <th colspan="2">Transaction Type</th>
            <th>Amount (GHC)</th>
            <th>Date</th>
            <th>Reference</th>
        </tr>
    </thead>
    <tbody>
        <?php
        if(!empty($transactData)){

            $count = $this->Paginator->counter("%start%");
            foreach( $transactData as $val ) {
                $semester = '';
                $acc_year = '';
                if(isset($val['Fee']['FeeType'])){
                    $reference = $val['Fee']['FeeType']['description'];
                }
                else{
                    $reference = '';
                }

                if(isset($val['Transaction']['AcademicSession']['semester'])){
                    $semester = 'Semester '.$val['Transaction']['AcademicSession']['semester'];
                }
                if(isset($val['Transaction']['AcademicSession']['acc_year'])){
                    $acc_year = $val['Transaction']['AcademicSession']['acc_year'].' Academic Year';
                }
            ?>
            <tr class="data-row">
                <td><?php echo $count++.'.'; ?></td>
                <td><?php echo $val['TransactionItem']['desc']; ?></td>
                <td class="col_amt"><?php echo $controller->formatNumber($val['TransactionItem']['credit_amt'],'money'); ?></td>
                <td><?php echo date("d M Y, g:ia", strtotime($val['Transaction']['created'])); ?></td>
                <td><?php echo $reference; ?></td>
            </tr>
                <?php
            }
        }
        else{
            ?>
        <tr>
            <td colspan="6" class="cell1">
                <div>
                    Sorry you do not have any transaction histories.
                </div>
            </td>
        </tr>
            <?php
        }
        ?>
    </tbody>
</table>

<div class="pagination">
    <ul>
        <?php
        echo $this->Paginator->first('First', null, null, array('tag' => 'li'));
        //echo $paginator->prev('Previous', null, null, array('tag'=>'li'));
        echo $this->Paginator->numbers(array('separator' => '', 'tag' => 'li'));
        //echo $paginator->next('Next', null, null, array('tag'=>'li'));
        echo $this->Paginator->last('Last', null, null, array('tag' => 'li'));
        ?>
    </ul>
</div>

<input type="hidden" id="print_history" value="<?php echo $this->Html->url(array('controller' => 'Student', 'action' => 'print_history')); ?>" />

<script type="text/javascript">
    $("#print_btn").click(function(){
        var action = $("#print_history").val();
        var url = action;
        window.open(url,action,"menubar=yes, width=600, height=500,location=no,status=no,scrollbars=yes,resizable=yes");
    });
</script>